package model

import (
	"smart-health-platforms/config"
	"time"
)

type MemberBenefitClaims struct {
	Id        int32     `gorm:"column:id;type:int;primaryKey;not null;" json:"id"`
	UserId    uint32    `gorm:"column:user_id;type:int UNSIGNED;comment:用户id;default:NULL;" json:"user_id"`                               // 用户id
	BenefitId uint32    `gorm:"column:benefit_id;type:int UNSIGNED;comment:权益id;default:NULL;" json:"benefit_id"`                         // 权益id
	CreatedAt time.Time `gorm:"column:created_at;type:datetime(3);comment:领取时间;not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"` // 领取时间
}

func (m *MemberBenefitClaims) TableName() string {
	return "member_benefit_claims"
}
func (m *MemberBenefitClaims) CreateBenefit() error {
	return config.DB.Create(&m).Error
}
func (m *MemberBenefitClaims) GetBenefit() error {
	return config.DB.Where("user_id = ? and benefit_id = ?", m.UserId, m.BenefitId).Find(&m).Error
}
